package com.wzu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzu.entity.Disease;
import com.wzu.mapper.DiseaseMapper;
import com.wzu.service.DiseaseService;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class DiseaseServiceImpl extends ServiceImpl<DiseaseMapper, Disease> implements DiseaseService {
    @Override
    public List<Disease> searchDiseases(String code, String pinyin, String name) {
        QueryWrapper<Disease> wrapper = new QueryWrapper<>();
        if (code != null && !code.isEmpty()) wrapper.like("disease_code", code);
        if (pinyin != null && !pinyin.isEmpty()) wrapper.like("pinyin_code", pinyin);
        if (name != null && !name.isEmpty()) wrapper.like("disease_name", name);
        return list(wrapper);
    }
    @Override
    public boolean addDisease(Disease disease) {
        // 编码唯一校验
        QueryWrapper<Disease> wrapper = new QueryWrapper<>();
        wrapper.eq("disease_code", disease.getDiseaseCode());
        if (count(wrapper) > 0) return false;
        return save(disease);
    }
    @Override
    public boolean updateDisease(Disease disease) {
        QueryWrapper<Disease> wrapper = new QueryWrapper<>();
        wrapper.eq("disease_code", disease.getDiseaseCode()).ne("id", disease.getId());
        if (count(wrapper) > 0) return false;
        return updateById(disease);
    }
    @Override
    public boolean deleteDisease(Long id) {
        return removeById(id);
    }
} 